<?php
namespace api\modules\v1\controllers;

use api\modules\v1\models\friend\Friend;
use api\modules\v1\models\friend\FriendApply;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;
use Yii;

/**
 * Default controller for the `v1` module
 */
class FriendController extends DefaultController
{

    public $modelClass = 'api\modules\v1\models\imFriend\ImFriend';

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }

    /* ======================  好友申请 ========================= */
    /**
     * 申请好友
     * @return array
     */
    public function actionApply() {
        if (Yii::$app->request->isPost) {
            return (new FriendApply())->apply();
        }
    }


    /**
     * 申请列表
     * @return array
     */
    public function actionApplyList()
    {
        if (Yii::$app->request->isGet) {
            return (new FriendApply())->getList();
        }

    }

    /**
     * 申请处理
     * @return array
     */
    public function actionApplyCheck()
    {
        if (Yii::$app->request->isPost) {
            return (new FriendApply())->check();
        }
    }

    /* ======================  好友关系 ========================= */
    /**
     * 好友列表
     * @return array
     */
    public function actionList()
    {
        if (Yii::$app->request->isGet) {
            return (new Friend())->getList();
        }

    }

    /**
     *  好友详情 与 删除好友
     * @param string $code
     * @return array
     */
    public function actionInfo($code = '')
    {
        if (Yii::$app->request->isGet) {
            return (new Friend())->info($code);
        }

        if (Yii::$app->request->isDelete) {
            return (new Friend())->del($code);
        }

    }

    /**
     * 修改备注
     * @return array
     */
    public function actionUpdateMark()
    {
        if (Yii::$app->request->isPost) {
            return (new Friend())->updateMark();
        }

    }




}
